package com.tzy.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tzy.entity.Cart;
import com.tzy.entity.OrderDetail;
import com.tzy.service.OrderDetailService;

/**
* <p>Title: ProductCartController</p> 
* <p>Description: </p> 
* @author  唐振耀 
* @date  2019年6月11日
*/
@Controller
public class ProductCartController {
	@Autowired
	private OrderDetailService ods;
	
	/**
	 * @param name
	 * @param request
	 * @param OD
	 * @return 把商品添加到购物车
	 */
	@RequestMapping("ShoppingCart")
	public String ShoppingCart(/* Integer user_id, */String name, /* Cart cl, */ HttpServletRequest request ,OrderDetail OD ) {
		request.getSession().setAttribute("category_name", name);		
        request.getSession().setAttribute("cl",OD);
        System.out.println("要输入购物车的信息2："+OD);   
        int cart = this.ods.addCartByUser_id(OD);
        System.out.println(cart);
        return "forward:/updateHome";
	}
	
	/**
	 * @param user_id
	 * @param model
	 * @return 购物车进行查封商品
	 */
	@RequestMapping("doCart")
	public String doCart(Integer user_id,Model model,HttpServletRequest request) {
		System.out.println("用户id"+user_id);
		List<OrderDetail> od = this.ods.selectCartByUser_id(user_id);
		System.out.println("123456789/*-+"+od);
		request.setAttribute("user_id", user_id);
		//model.addAttribute("od", od);
		request.setAttribute("od", od);
		//model.addAttribute("user_id", user_id);
		return "ShoppingCart";
	}
	
	/**
	 * @param user_id
	 * @param model
	 * @return 获取购物车数据到order
	 */
	@RequestMapping("toCart")
	public String selCart(Integer user_id,Model model) {
		System.out.println("用户id"+user_id);
		List<OrderDetail> od = this.ods.selectCartByUser_id(user_id);
		System.out.println("123456789/*-+"+od);
		model.addAttribute("od", od);
		model.addAttribute("user_id", user_id);
		return "order";
	}
	
	
	/**
	 * @param id
	 * @param user_id
	 * @return 删除购物车商品
	 */
	@RequestMapping("deleteOrderDetailById")
	public String deleteOrderDetailById(Integer id,Integer user_id) {
		System.out.println("商品ID和用户ID："+id+user_id);
		int od = this.ods.deleteOrderDetailById(id);
		return "forward:/doCart";
		
	}

}
